package control;
import java.util.ArrayList;

import model.*;
import db.*;

public class SalesOrderCtrl
{
	DBSalesOrder dbSal = new DBSalesOrder();
	
	public SalesOrderCtrl()
	{
		
	}
	
	public ArrayList<SalesOrder> getAllSalesOrders()
	{
		ArrayList<SalesOrder> allSal = new ArrayList<SalesOrder>();
		allSal = dbSal.getAllSalesOrders(false);
		return allSal;
	}
	
	public SalesOrder getSalesOrderId(String id)
	{
		return dbSal.getSalesOrderId(id, false);
	}
	
	public SalesOrder getSalesOrderCustomerId(String id)
	{
		return dbSal.getSalesOrderCustomerId(id, false);
	}
	
	public void insertSalesOrder(int id, String date, String deliveryStatus, String deliveryDate, double totalPrice, int customerId) throws Exception
	{
		SalesOrder toInsert = new SalesOrder();
		toInsert.setId(id);
		toInsert.setDate(date);
		toInsert.setDeliveryStatus(deliveryStatus);
		toInsert.setDeliveryDate(deliveryDate);
		toInsert.setTotalPrice(totalPrice);
		toInsert.setCustomerId(customerId);
		dbSal.insertSalesOrder(toInsert);
	}
	
	public int updateSalesOrder(int id, String date, String deliveryStatus, String deliveryDate, double totalPrice, int customerId)
	{
		SalesOrder sal = new SalesOrder();
		sal.setId(id);
		sal.setDate(date);
		sal.setDeliveryStatus(deliveryStatus);
		sal.setDeliveryDate(deliveryDate);
		sal.setTotalPrice(totalPrice);
		sal.setCustomerId(customerId);
		return dbSal.updateSalesOrder(sal);
	}
	
	public void deleteSalesOrder(String id)
	{
		dbSal.deleteSalesOrder(id);
	}
}
